**#Master do-file: Increasing Responsiveness of Civil Servants. A Field Experiment on Freedom of Information Compliance
*Authors: Carlos Scartascini and Paula Zamora

glo Folder 	="./Replication Package"
	glo Figures	= "$Folder/Figures"
	glo Tables	= "$Folder/Tables"
	cd "$Folder"

**#1. Create an indicator variable with the sample of agencies that received requests that were not denied before and after the intervention 

use "$Folder/Data_Civil_Servants_original.dta", clear
tab answer, miss
drop if answer==2
collapse agency, by(agency_string time)
bysort agency: gen Total=_N
bysort agency: gen Total2=_n
keep if Total==Total2
drop Total
gen sample = 1 if Total==2
distinct agency if sample==1 //94 agencies received requests before and after the intervention
keep if sample==1
keep sample agency 
merge 1:m agency using "$Folder/Data_Civil_Servants_original.dta", nogen //6,002 request matched. 117 not matched.
replace sample=. if answer==2
tab sample // 5,875 requests
labmask agency, values(agency_string)
gen post=time==1
gen treat_post=treatment*post
save "$Folder/Data_Civil_Servants_final.dta", replace

**#2. Calculate the number of business days and binary dependent variables 
gen open_request=date_response==.
gen business_days=date_response-date_reception

gen business_days_15=1 if business_days==15
gen business_days_25=1 if business_days==25
gen business_days_141516=1 if business_days==15 | business_days==14 | business_days==16
gen business_days_242526=1 if business_days==25 | business_days==24 | business_days==26
gen business_days_1415=1 if business_days==15 | business_days==14
gen business_days_2425=1 if business_days==25 | business_days==24

gen business_days_within_15=1 if business_days<=15
replace business_days_within_15=0 if business_days>15

gen business_days_within_25=1 if business_days<=25
replace business_days_within_25=0 if business_days>25

gen business_days_late=1 if business_days>25

foreach var in 15 25 141516 2425 242526 late {
	replace business_days_`var'=0 if business_days_`var'==.
}

gen comply=1 if date_response<=final_deadline
replace comply=0 if date_response>final_deadline

gen extension=1 if original_deadline_25!=.
replace extension=0 if original_deadline_25==.

label variable comply "Replied in time"
label variable extension "Request was granted an extension"
label variable complete "Complete answer"

**##Winsorize days
winsor business_days if sample==1,  gen(business_w5) p(.05) highonly

save "$Folder/Data_Civil_Servants_final.dta", replace

**#3. Calculate the number of requests received by an agency on a date 

use "$Folder/Data_Civil_Servants_final.dta", clear
gen agency_n_req_date=1
collapse (sum) agency_n_req_date, by(agency date_reception)
bysort agency (date_reception): gen agency_n_req_date_cum=sum(agency_n_req_date)
merge 1:m agency date_reception using "$Folder/Data_Civil_Servants_final.dta", nogen

gen agency_n_req_per_day=1 if agency_n_req_date==1
replace agency_n_req_per_day=2 if agency_n_req_date==2
replace agency_n_req_per_day=3 if agency_n_req_date>2 & agency_n_req_date<11
replace agency_n_req_per_day=4 if agency_n_req_date>10

label define agency_n_req_per_day 1 "1 request" 2 "2 requests on a day" 3 "3 to 10 requests on a day" 4 "More than 10 requests on a day", replace
label values agency_n_req_per_day agency_n_req_per_day

save "$Folder/Data_Civil_Servants_final.dta", replace

**#4. Calculate the percentage of requests that remained open when a new request was received. 
 
use "$Folder/Data_Civil_Servants_final.dta", clear
gen perc_open=agency_n_req_date_open/agency_n_req_date_cum*100 
gen perc_open_not_expired=agency_n_req_date_opennotexpired/agency_n_req_date_cum*100 
gen perc_open_expired=agency_n_req_date_openexpired/agency_n_req_date_cum*100 
gen perc_closed=agency_n_req_date_closed/agency_n_req_date_cum*100 

sort treatment agency date_reception date_response
save "$Folder/Data_Civil_Servants_final.dta", replace

**##Vextatious requesters
use "$Folder/Data_Civil_Servants_final.dta", clear
br if id_requester==3510
gen obs=1
collapse (sum) obs, by(id_requester agency date_reception)
sort id_requester agency date_reception

bysort id_requester agency: gen sequencerequestagency=obs if _n==1
bysort id_requester agency (date_reception): replace  sequencerequestagency=obs[_n]+ sequencerequestagency[_n-1] if _n>1

gen vex_req=1 if sequencerequestagency==1
replace vex_req=2 if sequencerequestagency==2
replace vex_req=3 if sequencerequestagency==3
replace vex_req=4 if sequencerequestagency>3 & sequencerequestagency<11
replace vex_req=5 if sequencerequestagency>10 & sequencerequestagency<21
replace vex_req=6 if sequencerequestagency>20

drop obs 

merge 1:m  id_requester agency date_reception using "$Folder/Data_Civil_Servants_final.dta", nogen
tab sequencerequestagency 
tab vex_req


bys agency: egen pre_back= mean(perc_open_expired) if time == 0
bys agency: egen pre_per= mean(perc_open_not_expired) if time == 0
bys agency: egen Total_requests= count(id_request) if time == 0

bysort agency: egen pre_backlog = mean(pre_back)
bysort agency: egen pre_percent_not_expired = mean(pre_per)
bysort agency: egen total_requests = mean(Total_requests)

drop pre_back Total_requests pre_per
label variable total_requests "Total n requests received before the intervention"
label variable pre_percent_not_expired "Mean of \% Pending Pre"
label variable pre_backlog "Mean of \% Backlog Pre"

save "$Folder/Data_Civil_Servants_final.dta", replace

**##Identify first treated request received by treated agencies. 
use "$Folder/Data_Civil_Servants_final.dta", clear
tab date_reception
keep if treatment==1
keep if sample==1 & time==1

collapse (min) date_reception, by(agency treatment)
rename date_reception agency_first_treated_request
keep agency*

merge 1:m agency using "$Folder/Data_Civil_Servants_final.dta", nogen

**##To analyze spillovers across requests within treated agencies: requests closer to the first treated request received by the agency with the new notification

gen bet_treated_and_received=agency_first_treated_request - date_reception

replace bet_treated_and_received=. if bet_treated_and_received<0 // The request was received after the first treated request.
replace bet_treated_and_received=. if date_response<agency_first_treated_request // The request was responded to before the first treated request arrived to the agency.

replace bet_treated_and_received=-bet_treated_and_received

label variable bet_treated_and_received "1 day closer"

save "$Folder/Data_Civil_Servants_final.dta", replace

**##Workshops

use "$Folder/Data_Civil_Servants_final.dta", clear

**###Participation of agencies in workshops

gen agency_participation_w=1 if Date_workshop_1_attended!=.
replace agency_participation_w=0 if Date_workshop_1_attended==.

**####Participation before the intervention started
gen agency_participation_w_b=1 if Date_workshop_1_attended<=`=date("06sep2018","DMY")'
forvalue i=1(1)8{
replace agency_participation_w_b=1 if Date_workshop_`i'_attended<=`=date("06sep2018","DMY")'	
}

replace agency_participation_w_b=0 if agency_participation_w_b==.
tab Date_workshop_1_attended if agency_participation_w_b==1

**####Participation after the intervention started
gen agency_participation_w_a=1 if Date_workshop_1_attended>`=date("06sep2018","DMY")' &  Date_workshop_1_attended!=.

forvalue i=1(1)8{
replace agency_participation_w_a=1 if Date_workshop_`i'_attended>`=date("06sep2018","DMY")' &  Date_workshop_`i'_attended!=.
}
replace agency_participation_w_a=0 if agency_participation_w_a==.

**###Requests influenced by a workshop

distinct agency_string if treatment==1 & Date_workshop_1_attended!=. & sample==1 // 27
distinct agency_string if treatment==0 & Date_workshop_1_attended!=. & sample==1 // 28

forvalues i=1(1)8{
gen date_W_`i'=bofd("FechaHabil",Date_workshop_`i'_attended)
}

format date_W* %tbFechaHabil
drop Date_workshop_*

gen influence_workshop_request=1 if date_reception>date_W_1 & date_W_1!=.

forvalues i=1(1)8{
	replace influence_workshop_request=1 if date_reception<date_W_`i' & date_W_`i'!=. & date_response>date_W_`i'
}

replace influence_workshop_request=0 if influence_workshop_request==.

replace influence_workshop_request=. if sample!=1

tab influence_workshop_request 
/*
Influence_W |
   _request |      Freq.     Percent        Cum.
------------+-----------------------------------
          0 |      3,430       58.38       58.38
          1 |      2,445       41.62      100.00
------------+-----------------------------------
      Total |      5,875      100.00
*/
sort order

order treatment ministry_code agency agency_string id_request time post treat_post  sample id_requester  type_requester  date_reception month_reception year_reception date_response business_days answer complete comply in_time_original business_days_15 business_days_25 business_days_141516 business_days_242526  business_days_1415 business_days_2425 business_days_within_15 business_days_within_25 perc* case* topic_category open_request business_days_late extension original_deadline* final_deadline business_w5 agency_n_req_date_openexpired agency_n_req_date_closed agency_n_req_date_open agency_n_req_date_opennotexpired

save "$Folder/Data_Civil_Servants_final.dta", replace

**#5. Section 4: Data Description

use "$Folder/Data_Civil_Servants_final.dta", clear
distinct agency if sample==1 //5,875 requests received by 94 agencies. 
tab time if sample==1 // 3,163 FOI requests received by government agencies before the experiment started (Jan. 2, 2017 and September 5, 2018), and 2,712 FOI requests received during the experiment (Sept. 6, 2018 and March 6, 2019).
tab open_request time if sample==1 // By November 27, 2019, the date on which we obtained the data, only 169 requests remained open: 76 of them were received before the experiment started, and 93 were received during the experiment

**##By November 27, 2019, when we obtained the data, all the 169 requests had already expired; they had exceeded the maximum deadline to respond to them.

preserve 
tab date_response
gen date_data=719 // Nov 27, 2019
format date_data %tbFechaHabil
gen days_data=date_data-date_reception
sum days_data if open_request==1 & sample==1 // Min is 182 days
restore

**##Requests that were responded to are classified in three cases: 

*Case I: comprises requests received and closed before the intervention started: 2,737 requests were received between January 2, 2017 and September 4, 2018. Agencies responded to these requests between January 9, 2017 and September 5, 2018.
tab case_1
tab date_reception if case_1==1
tab date_response if case_1==1

*Case II: comprises 350 requests received before the intervention started, between March 20, 2017 and September 5, 2018. These requests were answered after the intervention had already begun (between September 6, 2018, and July 19, 2019). 

tab case_2
tab date_reception if case_2==1
tab date_response if case_2==1

*Case III: 2,619 requests fall into \textit{Case III}. These were received during the experiment, between September 6, 2018 and March 6, 2019. Agencies responded to these requests between September 11, 2018 and October 9, 2019. 

tab case_3
tab date_reception if case_3==1
tab date_response if case_3==1

**##Type of requester:

*In the city of Buenos Aires, most FOI requests come from citizens (91.5\%), NGOs (4.3\%), and political actors (1.3\%).\footnote{Journalists and lawyers account for 0.8\%, and 0.9\%, respectively, and others (businesses, members of a community board, among others) account for 1.2\%.} 

tab type_requester
tab type_requester if sample==1

*The city government of Buenos Aires reported that 90.7\% of requests received a complete response, 5.6\% received a partial response, and 3.7\% were denied. However, only 71\% were responded in time. That is, they were replied to before 15 business days if an extension was not granted or replied to before the final deadline set by the extension, which is, in 75\% of the extended cases, 25 business days.\footnote{29.5\% of the requests were granted an extension.} 

tab answer if sample==1
tab comply if sample==1

preserve
gen dif_days=final_deadline-date_reception
tab dif_days if extension==1 & sample==1
restore

tab extension if sample==1

*In Buenos Aires, four out of fifteen topics account for 68\% of the FOI requests. The most prevalent topics for which the public files FOI requests (29.9\%) are permits, inspections, and infrastructure. For example, there are many requests for information regarding whether a commercial activity is permitted on a specific property.  The second most common topic  (17.9\%) is public administration. In this case, most requests are for information about social programs or the procurement process for public infrastructure. The third most popular topic  (10.9\%) is public space. In this case, most people file requests for information regarding the city's green spaces, parks, and squares. The fourth most common topic (9.4\%) is financial information. 80\% of these requests are related to budget execution of public resources.

distinct topic_category //15 topics
tab topic_category if sample==1, sort

*37$\%$ of the requests were the only ones received by an agency on that day; 18.7$\%$ were received on the same day as another request; and 44.3$\%$ arrived on a day when the agency received three requests or more

tab agency_n_req_date if sample==1

*Considering the whole sample, before and after the intervention, when an agency received a new request, on average, 72.8$\%$ of its requests had been answered, 21.4$\%$ were still pending, but not yet late, and 5.8$\%$ were already past the final deadline. 

sum perc_closed if sample==1
sum perc_open_not_expired if sample==1
sum perc_open_expired if sample==1

**##Figure 3
preserve
	do "$Folder/Do-files/Figure_8"
restore

**#7. Empirical Analysis

glo all_DV "business_w5 comply complete open_request extension business_days_within_15 business_days_within_25 business_days_15 business_days_25 business_days_141516 business_days_242526" 

glo all_binary "comply complete open_request extension business_days_within_15 business_days_within_25 business_days_15 business_days_25"

global binary_flexible "business_days_15 business_days_25 business_days_141516 business_days_242526" 

global ControlsA ib9.month_reception total_requests pre_backlog pre_percent_not_expired total_requests

global ControlsB ib9.month_reception total_requests i.type_request i.vex_req  i.topic i.agency_n_req_per_day i.ministry_code pre_percent_not_expired pre_backlog 

global math  "\$"

#delimit;
global labels "
       treatment "Treatment"
	   1.treatment "Treatment"
	   1.treatment#1.time "Treatment x Post"
	   1.time "Post"
	   1.influence_workshop_request "Request influeced by W."
	   
	   2.agency_n_req_date "2 requests on a day" 
	   3.agency_n_req_date "3 to 10 requests on a day" 
	   4.agency_n_req_date "$math > $math 10 requests on a day"
	   
	   2.vex_req "Same person: twice"
	   3.vex_req "Same person: three times"
	   4.vex_req "Same person: 4 to 10 times"
	   5.vex_req "Same person: 11 to 20 times"
	   6.vex_req "Same person: $math > $math 20 times"
	   
	   perc_open_not_expired "$math \% $math Open requests" 
	   perc_open_expired "$math \% $math Backlog"
	   perc_open_not_expired_2023 "$math \% $math Open requests" 
	   perc_open_expired_2023 "$math \% $math Backlog"
	   _cons "Constant"
	   n "Total number of requests"
	   comply "Proportion replied in time"
	   total_w_while_open "N. workshops"
	  
	   business_days "Business Days"
	   business_w5 "Average business days w5"
";
#delimit cr

**##Tables 1, 2, and 3: Main results
preserve
	do "$Folder/Do-files/Tables_123"
restore

**##Table 4: Accounting for the influence of the workshops
preserve
	do "$Folder/Do-files/Table_4"
restore

**##Table 5: Spillover within treated agencies
preserve
	do "$Folder/Do-files/Table_5"
restore

**##Tables B.1 and B.2: Balance Tests
preserve
	do "$Folder/Do-files/Tables_B1B2"
restore

**##Table C.1.: Power calculation
preserve 
	do "$Folder/Do-files/Table_C1"
restore 

**##Figure C.1.: Power calculation
preserve 
	do "$Folder/Do-files/Figure_C1"
restore 

**##Table D.1.: Agencies' participation in workshops
preserve 
	do "$Folder/Do-files/Table_D1.do"
restore

**##Table D.2.: Determinants of agency participation in workshops
preserve
	do "$Folder/Do-files/Table_D2.do"
restore

**##Table D.3.: Agencies' response to requests 
preserve
	do "$Folder/Do-files/Table_D3.do"
restore

**##Table D.4.: Agencies' response to requests 
preserve
	do "$Folder/Do-files/Table_D4.do"
restore

**##***DiD Model***

**##Table E.1.: Agencies' response to requests - Specific deadlines
preserve
	do "$Folder/Do-files/Table_E1.do"
restore

**##Table E.2.: Agencies' response to requests - Flexible deadlines
preserve
	do "$Folder/Do-files/Table_E2.do"
restore

**##Table E.3.  Agencies' response to requests considering workshop influence on requests
preserve
	do "$Folder/Do-files/Table_E3.do"
restore

**##Table E.4.: Agencies' response to requests controlling for the number of days spent in workshops
preserve
	do "$Folder/Do-files/Table_E4.do"
restore

**##Table E.5.: Interaction of the training workshops with the intervention
preserve
	do "$Folder/Do-files/Table_E5.do"
restore

**##Table E.6.: Results after dropping requests in Case II - DiD
preserve
	do "$Folder/Do-files/Table_E6.do"
restore

**##Table E.7.: Randomization Inference
preserve
	do "$Folder/Do-files/Table_E7_a.do"
	do "$Folder/Do-files/Table_E7_b.do"
restore

**##Additional figure in referee response
preserve
	do "$Folder/Do-files/Additional_figure_requestsovertime.do"
restore

